/**
 * Created by Administrator on 2017/1/17.
 */


module.exports = function(app) {
    return new Handler(app);
};

var Handler = function(app) {
    this.app = app;
};

var handler = Handler.prototype;


function RegisterHandler(name) {
    handler[name] = function(msg, session, next) {
        var room = session.room;

        var roomHandler = room["handle" + name.capWord()];
        if (!roomHandler || typeof (roomHandler) != 'function') {
            next(null, {code: Code.SUB_ROUTE_INVALID}); return;
        }

        room.beforeHandle(name);
        roomHandler.call(room, session.player, msg, function(resp) {
            next(null, resp);
        });
    }
}

RegisterHandler("playCard");
RegisterHandler("huTask");
RegisterHandler("pengTask");
RegisterHandler("gangTask");
RegisterHandler("chiTask");
RegisterHandler("passTask");
RegisterHandler("baoTing");
RegisterHandler("checkAndBaoTing");
RegisterHandler("queryTings");

RegisterHandler("selectPiao");

RegisterHandler("gmGetPublicCards");
RegisterHandler("gmSetPublicCards");

//TCMJ专属接口
RegisterHandler("selectHSZ");

//GYMJ专属接口
RegisterHandler("selectColor");
RegisterHandler("gift");
RegisterHandler("enjoy");
//HFMJ专属接口
RegisterHandler("shaiZiAndCards");
RegisterHandler("ShaiZiAndCards");

//HSMJ接口
RegisterHandler("PassLP");
RegisterHandler("LP");
RegisterHandler("PlaylzCard");